require 'gamifier/model'

module Gamifier
  class Collection
    include Gamifier::Model::FinderMethods
    
    attr_accessor :engine
    attr_reader :model

    def path
      model.path
    end

    def initialize(engine, model)
      @engine = engine
      @model = model
      self.extend model::FinderMethods
    end

    def build(entry)
      instance = model.new(entry)
      instance.engine = engine
      instance
    end

    def reset!(params = {})
      unless params.has_key?(:site)
        raise ArgumentError, "A :site parameter is required. Pass nil if you really want to delete all the objects of this kind, on all the sites."
      end
      all(params) do |entry|
        entry.destroy
      end
    end
  end
end